package com.example.c94s3plyhyfc.biz;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class MailServiceImpl{
    @Autowired
    private JavaMailSender mailSender;
    // Value 读取 yml 的配置项
    @Value("${mail.fromMail.addr}") // 发送者邮箱地址
    private String from;

    /**
     *
     * @param to        接受者
     * @param subject   标题
     * @param content   内容
     */
    public void sendSimpleMail(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);
        message.setText(content);
        mailSender.send(message);
    }
}
